{% extends "../../main.html" %}

{% block title %}{{ _("S.W.A.T.") }}{% end %}

{% block header %}
<script src="/static/js/pages/admin/upgrades/swat.js"></script>
{% end %}

{% block modals %}
<div id="accept-bribe-modal" class="modal hide fade" style="display: none;">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h3>{{ _("Accept Bribe?") }}</h3>
    </div>
    <div class="modal-body">
        <form id="accept-bribe-form" class="form-horizontal" action="/admin/upgrades/swat/accept" method="post">
            {% raw xsrf_form_html() %}
            <input id="accept-bribe-uuid" type="hidden" name="uuid" value="" />
        </form>
        <p>
            {{ _("Accept this bribe?") }}
        </p>
        <br />
    </div>
    <div class="modal-footer">
        <a href="#" class="btn" data-dismiss="modal">{{ _("Close") }}</a>
        <button id="accept-bribe-submit" class="btn btn-primary" type="button">
            {{ _("Confirm") }}
        </button>
    </div>
</div>
<div id="decline-bribe-modal" class="modal hide fade" style="display: none;">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h3>{{ _("Decline Bribe?") }}</h3>
    </div>
    <div class="modal-body">
        <form id="decline-bribe-form" class="form-horizontal" action="/admin/upgrades/swat/complete" method="post">
            {% raw xsrf_form_html() %}
            <input id="decline-bribe-uuid" type="hidden" name="uuid" value="" />
        </form>
        <p>
            {{ _("Decline this bribe?") }}
        </p>
        <br />
    </div>
    <div class="modal-footer">
        <a href="#" class="btn" data-dismiss="modal">{{ _("Close") }}</a>
        <button id="decline-bribe-submit" class="btn btn-primary" type="button">
            {{ _("Confirm") }}
        </button>
    </div>
</div>
<div id="complete-bribe-modal" class="modal hide fade" style="display: none;">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h3>{{ _("Complete Bribe") }}</h3>
    </div>
    <div class="modal-body">
        <form id="complete-bribe-form" class="form-horizontal" action="/admin/upgrades/swat/complete" method="post">
            {% raw xsrf_form_html() %}
            <input id="complete-bribe-uuid" type="hidden" name="uuid" value="" />
        </form>
        <p>
            {{ _("Complete this bribe?") }}
        </p>
        <br />
    </div>
    <div class="modal-footer">
        <a href="#" class="btn" data-dismiss="modal">{{ _("Close") }}</a>
        <button id="complete-bribe-submit" class="btn btn-primary" type="button">
            {{ _("Confirm") }}
        </button>
    </div>
</div>
{% end %}

{% block content %}
{% from models.Swat import Swat %}
<div class="container">
    <h1>
        <i class="fa fa-crosshairs"></i>
        {{ _("S.W.A.T.") }}
    </h1>
    <br />
    {% if errors is not None and len(errors) != 0 %}
        {% for error in errors %}
        <div class="alert alert-error">
            <a class="close" data-dismiss="alert" href="#">&times;</a>
            <h4 class="alert-heading">{{ _("ERROR") }}</h4>
            {{ error }}
        </div>
        {% end %}
    {% end %}
    <div class="well">
        <h3>{{ _("Pending Bribes") }}</h3>
        <hr>
        {% if len(pending_bribes) != 0 %}
            <table class="table table-striped">
                <thead>
                    <tr>
                        <th>#</th>
                        <th>{{ _("Created") }}</th>
                        <th>{{ _("User Handle") }}</th>
                        <th>{{ _("Target Handle") }}</th>
                        <th>{{ _("Bribe Amount") }}</th>
                        <th>{{ _("Previous Bribes") }}</th>
                        <th><!-- Accept Button --></th>
                        <th><!-- Decline Button --></th>
                    </tr>
                </thead>
                <tbody>
                    {% for index, swat in enumerate(pending_bribes) %}
                    <tr>
                        <td>{{ index + 1 }}</td>
                        <td>{{ swat.created }}</td>
                        <td>{{ swat.user.handle }}</td>
                        <td>{{ swat.target.handle }}</td>
                        <td>${{ swat.paid }}</td>
                        <td>{{ Swat.count_completed_by_target_id(swat.target.id) }}</td>
                        <td>
                            <a id="accept-bribe-button{{ index }}" class="btn btn-mini btn-success" data-toggle="modal" href="#accept-bribe-modal" data-uuid="{{ swat.uuid }}">
                                {{ _("Accept") }}
                            </a>
                        </td>
                        <td>
                            <a id="decline-bribe-button{{ index }}" class="btn btn-mini btn-danger" data-toggle="modal" href="#decline-bribe-modal" data-uuid="{{ swat.uuid }}">
                                {{ _("Decline") }}
                            </a>
                        </td>
                    </tr>
                    {% end %}
                </tbody>
            </table>
        {% else %}
            <br />{{ _("No Pending Bribes") }}...<br />
        {% end %}
    </div>
    <br />
    <div class="well">
        <h3>{{ _("Bribes in Progress") }}</h3>
        <hr>
        {% if len(in_progress_bribes) != 0 %}
            <table class="table table-striped">
                <thead>
                    <tr>
                        <th>#</th>
                        <th>{{ _("Created") }}</th>
                        <th>{{ _("User Handle") }}</th>
                        <th>{{ _("Target Handle") }}</th>
                        <th>{{ _("Bribe Amount") }}</th>
                        <th><!-- Complete Button --></th>
                    </tr>
                </thead>
                <tbody>
                    {% for index, swat in enumerate(in_progress_bribes) %}
                    <tr>
                        <td>{{ index + 1}}</td>
                        <td>{{ swat.created }}</td>
                        <td>{{ swat.user.handle }}</td>
                        <td>{{ swat.target.handle }}</td>
                        <td>${{ swat.paid }}</td>
                        <td>
                            <a id="complete-bribe-button{{ index }}" class="btn btn-mini" data-toggle="modal" href="#complete-bribe-modal" data-uuid="{{ swat.uuid }}">
                                {{ _("Complete") }}
                            </a>
                        </td>
                    </tr>
                    {% end %}
                </tbody>
            </table>
        {% else %}
            <br />{{ _("No Bribes in Progress") }}...<br />
        {% end %}
    </div>
    <br />
    <div class="well">
        <h3>{{ _("Completed Bribes") }}</h3>
        <hr>
        {% if len(completed_bribes) != 0 %}
            <table class="table table-striped">
                <thead>
                    <tr>
                        <th>#</th>
                        <th>{{ _("Created") }}</th>
                        <th>{{ _("User Handle") }}</th>
                        <th>{{ _("Target Handle") }}</th>
                        <th>{{ _("Bribe Amount") }}</th>
                        <th>{{ _("Outcome") }}</th>
                    </tr>
                </thead>
                <tbody>
                    {% for index, swat in enumerate(completed_bribes) %}
                        {% if swat.is_declined() %}
                            <tr class="error">
                        {% else %}
                            <tr class="success">
                        {% end %}
                            <td>{{ index + 1}}</td>
                            <td>{{ swat.created }}</td>
                            <td>{{ swat.user.handle }}</td>
                            <td>{{ swat.target.handle }}</td>
                            <td>${{ swat.paid }}</td>
                            {% if swat.is_declined() %}
                                <td>{{ _("Declined") }}</td>
                            {% else %}
                                <td>{{ _("Accepted") }}</td>
                            {% end %}
                        </tr>
                    {% end %}
                </tbody>
            </table>
        {% else %}
            <br />{{ _("No Completed Bribes") }}...<br />
        {% end %}
    </div>
</div>
{% end %}
